Page({
    data: {
        ids: [ 0 ],
        id: "",
        list: [],
        name: "",
        mobile: "",
        page_loading: !1,
        detail: "",
        style: "padding-left: 0;",
        order_no: "",
        order: {}
    },
    onLoad: function(t) {
        t.order_no && (this.setData({
            order_no: t.order_no
        }), this.getDistrict());
    },
    getDistrict: function() {
        var t = this;
        getApp().request({
            url: getApp().apiUrl.default.district,
            method: "get"
        }).then(function(e) {
            if (getApp().iView.$Toast.hide(), 0 == e.data.code) {
                var a = e.data.data.list;
                t.setData({
                    list: a
                }), t.getList();
            } else getApp().iView.$Toast({
                content: e.data.msg,
                duration: 2,
                type: "warning"
            });
        }).catch(function(t) {
            getApp().iView.$Toast({
                content: t.data.msg,
                duration: 2,
                type: "error"
            });
        });
    },
    getList: function() {
        var t = this;
        getApp().iView.$Toast({
            type: "loading",
            duration: 0
        }), getApp().request({
            url: getApp().apiUrl.app_admin.order,
            data: {
                status: "-1",
                keyword: t.data.order_no
            },
            method: "post"
        }).then(function(e) {
            if (getApp().iView.$Toast.hide(), 0 == e.data.code) {
                var a = e.data.data.list[0], i = a.address.trim().split(" "), d = [];
                t.data.list.forEach(function(t) {
                    t.name == i[0] && (d[0] = t.id, t.list.forEach(function(t) {
                        t.name == i[1] && (d[1] = t.id, t.list.forEach(function(t) {
                            t.name == i[2] && (d[2] = t.id);
                        }));
                    }));
                }), t.setData({
                    name: a.name,
                    mobile: a.mobile,
                    order: a,
                    ids: d,
                    detail: i[i.length - 1]
                });
            } else getApp().iView.$Toast({
                content: e.data.msg,
                duration: 2,
                type: "warning"
            });
        }).catch(function(t) {
            getApp().iView.$Toast({
                content: t.data.msg,
                duration: 2,
                type: "error"
            });
        });
    },
    areaEvent: function(t) {
        t.detail && this.setData({
            province: t.detail.province.name,
            city: t.detail.city.name,
            district: t.detail.district.name
        });
    },
    onReady: function(t) {
        this.setData({
            page_loading: !1
        });
    },
    saveAddress: function(t) {
        var e = this;
        e.data.province ? (getApp().iView.$Toast({
            content: "加载中",
            type: "loading",
            duration: 0
        }), getApp().request({
            url: getApp().apiUrl.app_admin.update_address,
            method: "POST",
            data: {
                order_id: e.data.order.id,
                name: t.detail.value.name,
                mobile: t.detail.value.mobile,
                province: e.data.province,
                city: e.data.city,
                district: e.data.district,
                address: t.detail.value.detail
            }
        }).then(function(t) {
            getApp().iView.$Toast.hide(), getApp().iView.$Toast({
                content: t.data.msg
            }), 0 == t.data.code && setTimeout(function() {
                getApp().api.navigateBack();
            }, 500);
        })) : getApp().iView.$Toast({
            content: "地区不能为空"
        });
    }
});